package com.youdianda.controller;


import com.youdianda.dto.ArticleDto;
import com.youdianda.dto.ArticlePageDto;
import com.youdianda.dto.RegDto;
import com.youdianda.result.Result;
import com.youdianda.service.YddArticleService;
import com.youdianda.service.IYddUserService;
import com.youdianda.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author mosen
 * @since 2023-05-15
 */
@RestController
@RequestMapping("/index")
@Slf4j
public class YJJYddArticleController {

    @Autowired
    private YddArticleService yddArticleService;
    @Autowired
    private IYddUserService iYddUserService;


    /**
     * 查询热门文章
     * @param articlePageDto
     * @return
     */
    @GetMapping("/new")
    public Result<YddArticleVo> getNew(ArticlePageDto articlePageDto){
       // log.error("查询热门文章：{}", articlePageDto);
        YddArticleVo yddArticleVo= yddArticleService.getArticle(articlePageDto);
        //log.error("查询数据：{}",articlePageDto);
        return Result.success(yddArticleVo);
    }

    @GetMapping("/list")
    public Result<ListVo> getList( ArticleDto articleDto){
        ListVo ListVo = yddArticleService.getArticleList(articleDto);
        return Result.success(ListVo);

    }

    /**
     * 注册
     * @param regDto
     * @return
     */
    @PostMapping("/reg")
    public Result<YddUserTokenVo> reg(@RequestBody RegDto regDto){
        YddUserTokenVo yddUserTokenVo = iYddUserService.reg(regDto);
        return Result.success(yddUserTokenVo);

    }

    /**
     * 最新文章
     * @return
     */
    @GetMapping("/hot")
    public Result<YddArticleHotVo> getnew(){
        YddArticleHotVo hot = yddArticleService.getNew();
        return Result.success(hot);

    }

    /**
     * 推荐文章
     * @return
     */
    @GetMapping("/recommend")
    public Result<YddArticleHotVo>getRecommend(){
        YddArticleHotVo hot = yddArticleService.getArticleHot();
        return Result.success(hot);

    }

    /**
     * 首页和全局数据
     * @return
     */
    @GetMapping("/index")
    public Result<ArticleIndexVo> getIndex(){
        ArticleIndexVo articleIndexVo= yddArticleService.getIndex();
        return Result.success(articleIndexVo);

    }

  @GetMapping("show")
    public Result<ShowVo> show(Integer id){
         ShowVo showVo= yddArticleService.getShow(id);
         return Result.success(showVo);

  }

}
